#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2018/3/5 0005 9:58
# @Author  : Arliki
# @email   : hkdnxycz@outlook.com
# @File    : for_pandas
import pandas as pd
import random as rd

import os


def get_price(pclass):
    if pclass == 1:
        return '%.2f' % (rd.randint(5, 15) + rd.randint(10, 99) / 100)
    elif pclass == 2:
        return '%.2f' % (rd.randint(16, 40) + rd.randint(10, 99) / 100)
    elif pclass == 3:
        return '%.2f' % (rd.randint(41, 80) + rd.randint(10, 99) / 100)

def run():
    a = rd.choice(['0', '0', '0', '0', '1', '1', '2', '2', '3', '4', '5'])
    b = rd.choice(['0', '0', '0', '0', '1', '1', '2', '2', '3', '4', '5'])
    c = get_price(2)
    d = rd.choice([0, 0, 0, 0, 1, 1, 1, 2, 3, 4, ])
    e = rd.randint(100000, 400000)
    print(a)
    data = pd.DataFrame([{"测试1": a, 'test1': b, "測試1": c, "D": d, "E": e}])
    print(data)
    # if (os.path.exists('test.csv')):
    #     data.to_csv("test.csv", index=False, sep=",", encoding="utf-8", mode='a', header=None)
    # else:
    #     data.to_csv("test.csv", index=False, sep=",", encoding="utf-8", mode='a')


def run2():
    res = pd.read_csv("test.csv")
    # print(res.head())
    # print(list(map(lambda x:res.columns[x],range(len(res.columns))))) #返回行名称
    print(list(res.columns))  # 返回行名称
    # print(res.loc[1])   #根据索引返回值
    # print(res[0:1])       #返回行切片
    # print(res.iloc[0:2,0:2]) #返回指定行 列数据
    # print(res["D"]/100)     #对某一列运算
    # print(res[0]/100)     #对某一行运算
    print(res.sort_values("D", inplace=False, ascending=False))  # 排序 是否原地替换 降序


if __name__ == '__main__':
    run()
    # run2()
